import moment from "moment";
import { Tag, Button } from "antd";
//分类column
export const userColumn = ({ openEditDialog }) => {
  const columns = [
    {
      align: "center",
      title: "头像",
      dataIndex: "avatar",
      render: (avatar) => {
        return (
          <img
            src={avatar}
            style={{ width: "50x", height: "50px", borderRadius: "50%" }}
          ></img>
        );
      },
    },
    {
      align: "center",
      title: "昵称",
      render: (row) => {
        return row.nickname || row.username;
      },
    },
    {
      align: "center",
      title: "登录方式",
      dataIndex: "loginType",
      render: (type) => {
        let arr = [
          { color: "blue", name: "账号" },
          { color: "red", name: "码云gitee" },
        ];
        return (
          <Tag color={arr[type - 1].color}>{arr[type - 1].name}</Tag> || "--"
        );
      },
    },
    {
      align: "center",
      title: "登录IP",
      dataIndex: "ip",
    },
    {
      align: "center",
      title: "登录地址",
      dataIndex: "ip_address",
    },
    {
      align: "center",
      title: "创建时间",
      render: (row) => {
        if (!row.createTime) {
          return "--";
        } else {
          return moment(parseInt(row.createTime)).format("YYYY-MM-DD HH:mm:ss");
        }
      },
    },
    {
      align: "center",
      title: "最后登录时间",
      render: (row) => {
        if (!row.lastLoginTime) {
          return "--";
        } else {
          return moment(parseInt(row.lastLoginTime)).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        }
      },
    },
    {
      title: "操作",
      render: (row) => {
        return (
          <>
            <Button
              style={{ marginRight: "10px" }}
              onClick={() => openEditDialog(row)}
            >
              编辑
            </Button>
          </>
        );
      },
    },
  ];

  return columns;
};

export const roleColumn = () => {
  const columns = [
    {
      align: "center",
      title: "编码",
      dataIndex: "remarks",
    },
    {
      title: "名称",
      dataIndex: "name",
    },
    {
      align: "center",
      title: "创建时间",
      render: (row) => {
        if (!row.create_time) {
          return "--";
        } else {
          return moment(parseInt(row.create_time)).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        }
      },
    },
  ];
  return columns;
};

export const limitColumn = ({ handleChildrenAdd,handleEdit,handleDelete }) => {
  const columns = [
    {
      align: "center",
      title: "权限名称",
      dataIndex: "name",
    },
    {
      align: "center",
      title: "权限标识",
      dataIndex: "sign",
    },
    {
      align: "center",
      title: "权限描述",
      dataIndex: "description",
    },
    {
      align: "center",
      title: "操作",
      render: (row) => {
        return (
          <>
            {!row.parentId ? (
              <Button
                type="primary"
                size="small"
                style={{ marginRight: "10px" }}
                onClick={() => handleChildrenAdd(row)}
              >
                添加
              </Button>
            ) : null}
            <Button type="primary" size="small" style={{ marginRight: "10px" }} onClick={()=>handleEdit(row)} >
              编辑
            </Button>
            <Button
              type="primary"
              size="small"
              style={{ marginRight: "10px" }}
              danger
              onClick={()=>handleDelete(row)}
            >
              删除
            </Button>
          </>
        );
      },
    },
  ];
  return columns;
};
